package com.rimi.lyingGoShoppingMall.service.impl;

import com.rimi.lyingGoShoppingMall.bean.User;
import com.rimi.lyingGoShoppingMall.mapper.UserMapper;
import com.rimi.lyingGoShoppingMall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * @author 61919
 * @date 2020/3/2
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * 查询所有的用户
     *
     * @return
     */
    @Override
    public List<User> findAllUser() {
        return userMapper.findAll();
    }

    /**
     * 登录账户
     *
     * @param user
     * @return
     */
    @Override
    public boolean login(User user) {
        if(Objects.isNull(user) || Objects.isNull(user.getUUsername()) || Objects.isNull(user.getUPassword())) {
            return false;
        }
        User userByUsernameAndPassword = userMapper.findUserByUsernameAndPassword(user);

        if(Objects.isNull(userByUsernameAndPassword)) {
            return false;
        }
        else {
            return true;
        }
    }
}
